$(document).ready(function() {	

	//第一次查询，无参数查询
	$.ajax( {
		type : "post",
		url : "wsq/Sched_find.action",
		success : showData
	});
	
	$("#query").click(function(){
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		var id=$("#id").val();
		var id=$("#scTime").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#SchedTable").fadeIn("fast");
		$("#loadingSched").show();
		$.ajax({
  			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{
			      "UId":UId,"duId":duId,"dsName1":dsName,"id":id,
 				  "timeStart":timeStart,
 				  "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#firstPage").click(function(){
		var total=$("#total").text();
		var page=1;
		var maxRow=$("#maxRow").text();
		var id=$("#id").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listSched").empty();
		$("#loadingSched").fadeIn("slow");
		$.ajax({
  			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"id":id,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#prePage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		var maxRow=$("#maxRow").text();
		var id=$("#id").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		page=(parseInt(page)-1);
		$("#listSched").empty();
		$("#loadingSched").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"id":id,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#nextPage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var id=$("#id").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listSched").empty();
		$("#loadingSched").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"id":id,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#lastPage").click(function(){
		var total=$("#total").text();
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var id=$("#id").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listSched").empty();
		$("#loadingSched").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#jumpPage").click(function(){
		var total=$("#total").text();
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		var id=$("#id").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();		
		var page=$("#jump").val();
		
		if(page>pageCount){
			alert("jumpPage > pageCount");
			return;
		}
		$("#listSched").empty();
		$("#loadingSched").fadeIn("fast");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"id":id,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	function showData(data){
		$("#listSched").empty();	
		if(data.pageUtil.list.length==0){
			$("#loadingSched").hide();
			$("#noneSched").show();
		}else{
			$("#listSched").hide();
			$("#noneSched").hide();
		    $("#loadingSched").hide();
		    $.each(data.pageUtil.list,function(i,n){
				fillDataToHtml(n.id.scTime,n.tbDuty.duId, n.tbDetailShift.dsName, n.tbUser.UName,n.tbUser.UName);
		  	});
		$("#listSched").show();
		$("#total").text(data.pageUtil.total);
		$("#page").text(data.pageUtil.page);
		$("#pageCount").text(Math.ceil(data.pageUtil.total/20));
		$("#maxRow").text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(scTime,duId,dsName,UName){
		var strHtml="<tr>";	
		strHtml+="<td ><div>"+scTime.replace(/T/," ")+"</div></td>";
		strHtml+="<td ><div>"+duId+"</div></td>";	
		strHtml+="<td ><div>"+dsName+"</div></td>";
		strHtml+="<td ><div>"+UName+"</div></td>";		
        strHtml+="</tr>";
        $("#listSched").append(strHtml);
	}
});